<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

//商品品牌控制器

class Brand extends Admin_Controller{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('admin/brand_model');
        $this->load->library('pagination');
    }
    //商品品牌信息
    public function index()
    {
        $data['brands'] = $this->brand_model->page_brand();
        $this->load->view('product-brand.html',$data);
    }

    public function add(){
        #完成上传图片
        $config['upload_path'] = './public/uploads/';
        if(!file_exists('public/uploads')){
            mkdir('public/uploads',0777,true);//存储路径
        }
        #完成上传图片
        $config['allowed_types'] = 'gif|jpg|png|jpeg|x-png|pjpeg';
        $config['max_width']  = '3000';
        $config['overwrite']  = FALSE;
        $config['encrypt_name']  = TRUE; //开启重命名
        $this->load->library('upload',$config);
        #配置上传相关参数
        if ($this->upload->do_upload('logo')) {
            # 上传成功，获取文件名
            $fileinfo = $this->upload->data();
            $data['logo'] = $fileinfo['file_name'];
            #获取表单提交数据
            $data['brand_name'] = $this->input->post('brand_name');
            /*$data['url'] = $this->input->post('url');
            $data['brand_desc'] = $this->input->post('brand_desc');
            $data['sort_order'] = $this->input->post('sort_order');
            $data['is_show'] = $this->input->post('is_show');*/

            #调用品牌模型完成插入动作
            if ($this->brand_model->add_brand($data)) {
                /*$data['message'] = '添加品牌成功';
                $data['wait'] = 3;
                $data['url'] = site_url('admin/brand/index');
                $this->load->view('message.html',$data);*/
                var_dump('添加品牌成功');
            } else {
                /*$data['message'] = '添加品牌失败';
                $data['wait'] = 3;
                $data['url'] = site_url('admin/brand/add');
                $this->load->view('message.html',$data);*/
                var_dump('添加品牌失败');
            }
        } else {
            # 上传失败
            $data['message'] = $this->upload->display_errors();
            /*$data['wait'] = 3;
            $data['url'] = site_url('admin/brand/add');
            $this->load->view('message.html',$data);*/
            var_dump($data);
        }
    }



}